package ObjectManager;
import javax.microedition.amms.control.audio3d.ObstructionControl;

public class AnimationObject extends ObjectGame implements Runnable {
    public boolean isRunning = false;
    public int delay;
    private boolean isRepeat = false;

    public AnimationObject(int frameWidth, int frameHeight, String imgSpriteSrc, int delay) {
        super(imgSpriteSrc, frameWidth, frameHeight);
        this.delay = delay;
    }
    
    public void Start(boolean repeat){
        isRepeat = repeat;
        isRunning = true;
        objSprite.setFrame(0);
        Thread t = new Thread(this);
        t.start();
    }
    
    public void Stop(){
        isRunning = false;
    }

    public void run() {
        while(isRunning){
            if(objSprite.getFrame() == objSprite.getFrameSequenceLength() - 1 && !isRepeat){
                isRunning = false;
            }
            else
                objSprite.nextFrame();
            try{
                Thread.currentThread().sleep(delay);
            }
            catch(Exception ex){}
        }
    }
}
